<?php
/**
 * Description of ModuleTestcase
 *
 * @author joona
 */
class Lib_AcceptanceTestcase extends PHPUnit_Framework_TestCase
{
    public static function setUpBeforeClass()
    {
        Lib_RegistryModifier::backupApplicationINI();
        Lib_RegistryModifier::modifyApplicationINI(
            array(
                'DB_USER = sweatshop' => 'DB_USER = root',
                'DB_PASS = letmein' => 'DB_PASS = ',
                'DB_NAME = sweatshop' => 'DB_NAME = test_sweatshop',
                'sweatshop_system.log' => 'sweatshop_system_test.log',
                'sweatshop_query.log' =>  'sweatshop_query_test.log',
                'sweatshop_query_error.log' => 'sweatshop_query_error_test.log',
            )
        );
        Core_Registry::reset();
        Lib_QueryWrapper::setUp('root', null, 'test_sweatshop', 'localhost');
        Lib_QueryWrapper::createTestDatabase();
    }

    /**
     *
     * @param String $controllerName
     * @param Array $fakePostParams
     * @param Array $fakeGetParams
     * @return Core_Controller
     */
    protected static function initController(
            $controllerName, $fakePostParams = array(),$fakeGetParams = array())
    {
        $requestObj = new Core_Request('/', $fakeGetParams, $fakePostParams);
        $controllerClass = "Controller_$controllerName";
        return new $controllerClass($requestObj);
    }

    public static function teardownAfterClass()
    {
        Lib_QueryWrapper::dropTestDatabase();
        Lib_RegistryModifier::returnOriginalApplicationINI();
        Core_Registry::reset();
    }

    protected function assertStringsEqualIgnoreEmptyLines($expected, $actual, $message= null)
    {

        $expected = preg_replace("/(^[\r\n]*|[\r\n]+)[\s\t]*[\r\n]+/", "\n", $expected);
        $actual = preg_replace("/(^[\r\n]*|[\r\n]+)[\s\t]*[\r\n]+/", "\n", $actual);
        $this->assertEquals($expected, $actual, $message);
    }

    protected static function getOutput()
    {
        return ob_get_contents();
    }
}
